
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>创建群集 · docker swarm实践文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Carey">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="portainer.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://carey.akhack.com" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础环境
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../base_book/环境介绍.html">
            
                <a href="../base_book/环境介绍.html">
            
                    
                    环境介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../base_book/环境准备.html">
            
                <a href="../base_book/环境准备.html">
            
                    
                    基础准备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../base_book/安装docker.html">
            
                <a href="../base_book/安装docker.html">
            
                    
                    安装 docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../base_book/compose_file.html">
            
                <a href="../base_book/compose_file.html">
            
                    
                    compose file文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../base_book/registry仓库管理.html">
            
                <a href="../base_book/registry仓库管理.html">
            
                    
                    registry管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    swarm 群集
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="创建群集.html">
            
                <a href="创建群集.html">
            
                    
                    创建群集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="portainer.html">
            
                <a href="portainer.html">
            
                    
                    swarm管理工具Portainer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="群集监控.html">
            
                <a href="群集监控.html">
            
                    
                    cAdvisor InfluxDB Grafana搭建监控平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="telegraf.html">
            
                <a href="telegraf.html">
            
                    
                    Telegraf监控容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Chronograf.html">
            
                <a href="Chronograf.html">
            
                    
                    Chronograf显示监控数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    swarm service
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../service_book/nginx.html">
            
                <a href="../service_book/nginx.html">
            
                    
                    部署nginx服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    swarm stack
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../swarm_stack/lnmpwordpress.html">
            
                <a href="../swarm_stack/lnmpwordpress.html">
            
                    
                    部署wordpress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../swarm_stack/build_eureka.md">
            
                <span>
            
                    
                    部署eureka
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >创建群集</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x521B;&#x5EFA;&#x7FA4;&#x96C6;">&#x521B;&#x5EFA;&#x7FA4;&#x96C6;</h1>
<h2 id="&#x521D;&#x59CB;&#x5316;&#x7FA4;&#x96C6;">&#x521D;&#x59CB;&#x5316;&#x7FA4;&#x96C6;</h2>
<p>master &#x4E3B;&#x673A;&#x6267;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;</p>
<pre><code>$ docker swarm init --advertise-addr 10.0.20.120
Swarm initialized: current node (w64t4fblkpuyj0jjk3g47df6v) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2z52uy5clu57n7tax3wmf97qx3ohiskmu0an6bz3w96kmx782z-b9m2k35lwd5tmu6s3h795omwp 10.0.20.120:2377

To add a manager to this swarm, run &apos;docker swarm join-token manager&apos; and follow the instructions.
</code></pre><blockquote>
<p><strong>[info] <code>--advertise-addr</code> &#x914D;&#x7F6E;master&#x53D1;&#x5E03;&#x5730;&#x5740;&#xFF0C;&#x5176;&#x4ED6;&#x8282;&#x70B9;&#x5FC5;&#x987B;&#x80FD;&#x591F;&#x8BBF;&#x95EE;&#x8BE5;ip&#xFF0C;&#x624D;&#x80FD;&#x52A0;&#x5165;&#x7FA4;&#x96C6;</strong></p>
</blockquote>
<p>&#x8F93;&#x51FA;&#x5305;&#x62EC;&#x5176;&#x4ED6;&#x8282;&#x70B9;&#x52A0;&#x5165;&#x8BE5;&#x7FA4;&#x96C6;&#x7684;&#x5B8C;&#x6574;&#x547D;&#x4EE4;&#x548C;token&#x3002;&#x540E;&#x7EED;&#x67E5;&#x770B;&#x4F7F;&#x7528;<code>docker swarm join-token manager</code></p>
<h1 id="&#x67E5;&#x770B;&#x5F53;&#x524D;swarm&#x72B6;&#x6001;">&#x67E5;&#x770B;&#x5F53;&#x524D;swarm&#x72B6;&#x6001;</h1>
<pre><code>$ docker info
Swarm: active
 NodeID: w64t4fblkpuyj0jjk3g47df6v
 Is Manager: true
 ClusterID: hlgjh2b5cbuzzt756m6d9au8e
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 10.0.20.120
 Manager Addresses:
  10.0.20.120:2377
</code></pre><h2 id="&#x67E5;&#x770B;&#x5F53;&#x524D;&#x8282;&#x70B9;">&#x67E5;&#x770B;&#x5F53;&#x524D;&#x8282;&#x70B9;</h2>
<pre><code>$  docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
w64t4fblkpuyj0jjk3g47df6v *   master              Ready               Active              Leader              18.03.0-ce
</code></pre><blockquote>
<p><strong>[info] &apos;*&apos; &#x8868;&#x793A;&#x5F53;&#x524D;&#x8FDE;&#x63A5;&#x7684;&#x8282;&#x70B9; </strong></p>
</blockquote>
<h2 id="&#x6DFB;&#x52A0;&#x8282;&#x70B9;">&#x6DFB;&#x52A0;&#x8282;&#x70B9;</h2>
<pre><code>
docker swarm join --token SWMTKN-1-2z52uy5clu57n7tax3wmf97qx3ohiskmu0an6bz3w96kmx782z-b9m2k35lwd5tmu6s3h795omwp 10.0.20.120:2377
</code></pre><p>&#x67E5;&#x770B;&#x5F53;&#x524D;&#x8282;&#x70B9;&#xFF0C;&#x53D1;&#x73B0;&#x5176;&#x4ED6;&#x4E09;&#x53F0;&#x8282;&#x70B9;&#x5DF2;&#x52A0;&#x5165;&#x5F53;&#x524D;&#x7FA4;&#x96C6;</p>
<pre><code>$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
w64t4fblkpuyj0jjk3g47df6v *   master              Ready               Active              Leader              18.03.0-ce
y3lswmm2qsuqvi0k55digfvjn     ndoe2               Ready               Active                                  18.03.0-ce
kreazv2yearuk14ovl06lri3z     ndoe3               Ready               Active                                  18.03.0-ce
v5xx8zo3hf19g6olxpzpjvxj1     node1               Ready               Active                                  18.03.0-ce
</code></pre><h2 id="&#x4FEE;&#x6539;master&#x53EA;&#x5177;&#x5907;&#x7BA1;&#x7406;&#x529F;&#x80FD;">&#x4FEE;&#x6539;master&#x53EA;&#x5177;&#x5907;&#x7BA1;&#x7406;&#x529F;&#x80FD;</h2>
<blockquote>
<p><strong>[info]  node&#x7684;<code>AVAILABILITY</code>&#x6709;&#x4E09;&#x79CD;&#x72B6;&#x6001;&#xFF1A;<code>Active</code>&#x3001;<code>Pause</code>&#x3001;<code>Drain</code></strong></p>
</blockquote>
<p>&#x5E38;&#x89C1;&#x7684;&#x53D8;&#x66F4;&#x64CD;&#x4F5C;&#xFF1A;</p>
<ul>
<li>&#x8BBE;&#x7F6E;Manager Node&#x53EA;&#x5177;&#x6709;&#x7BA1;&#x7406;&#x529F;&#x80FD;</li>
<li>&#x5BF9;&#x670D;&#x52A1;&#x8FDB;&#x884C;&#x505C;&#x673A;&#x7EF4;&#x62A4;&#xFF0C;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;<code>AVAILABILITY</code>&#x4E3A;<code>Drain</code>&#x72B6;&#x6001;</li>
<li>&#x6682;&#x505C;&#x4E00;&#x4E2A;Node&#xFF0C;&#x7136;&#x540E;&#x8BE5;Node&#x5C31;&#x4E0D;&#x518D;&#x63A5;&#x6536;&#x65B0;&#x7684;<code>Task</code></li>
<li>&#x6062;&#x590D;&#x4E00;&#x4E2A;&#x4E0D;&#x53EF;&#x7528;&#x6216;&#x8005;&#x6682;&#x505C;&#x7684;Node</li>
</ul>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x4F7F;Manager Node&#x53EA;&#x5177;&#x5907;&#x7BA1;&#x7406;&#x529F;&#x80FD;&#xFF0C;&#x4E0D;&#x80FD;&#x90E8;&#x7F72;&#x5B9E;&#x9645;&#x7684;Docker&#x5BB9;&#x5668;&#x6765;&#x8FD0;&#x884C;&#x670D;&#x52A1;&#xFF0C;&#x6267;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;:</p>
<pre><code>docker node update --availability drain master
</code></pre><h2 id="&#x6DFB;&#x52A0;&#x6807;&#x7B7E;&#x5143;&#x6570;&#x636E;">&#x6DFB;&#x52A0;&#x6807;&#x7B7E;&#x5143;&#x6570;&#x636E;</h2>
<pre><code>docker node update --label-add &#x952E;&#x540D;&#x79F0;=&#x503C; node
</code></pre><h2 id="&#x4FEE;&#x6539;&#x7FA4;&#x96C6;&#x8BC1;&#x4E66;&#x8FC7;&#x671F;&#x65F6;&#x95F4;">&#x4FEE;&#x6539;&#x7FA4;&#x96C6;&#x8BC1;&#x4E66;&#x8FC7;&#x671F;&#x65F6;&#x95F4;</h2>
<pre><code>docker swarm update --cert-expiry 87600h
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="portainer.html" class="navigation navigation-next navigation-unique" aria-label="Next page: swarm管理工具Portainer">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"创建群集","level":"1.3.1","depth":2,"next":{"title":"swarm管理工具Portainer","level":"1.3.2","depth":2,"path":"swarm_book/portainer.md","ref":"swarm_book/portainer.md","articles":[]},"previous":{"title":"swarm 群集","level":"1.3","depth":1,"ref":"","articles":[{"title":"创建群集","level":"1.3.1","depth":2,"path":"swarm_book/创建群集.md","ref":"swarm_book/创建群集.md","articles":[]},{"title":"swarm管理工具Portainer","level":"1.3.2","depth":2,"path":"swarm_book/portainer.md","ref":"swarm_book/portainer.md","articles":[]},{"title":"cAdvisor InfluxDB Grafana搭建监控平台","level":"1.3.3","depth":2,"path":"swarm_book/群集监控.md","ref":"swarm_book/群集监控.md","articles":[]},{"title":"Telegraf监控容器","level":"1.3.4","depth":2,"path":"swarm_book/telegraf.md","ref":"swarm_book/telegraf.md","articles":[]},{"title":"Chronograf显示监控数据","level":"1.3.5","depth":2,"path":"swarm_book/Chronograf.md","ref":"swarm_book/Chronograf.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["emphasize","alerts","code","-lunr","-search","search-plus","splitter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Carey","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"docker swarm实践文档","language":"zh-hans","links":{"sidebar":{"Home":"http://carey.akhack.com"}},"gitbook":"*"},"file":{"path":"swarm_book/创建群集.md","mtime":"2018-07-06T03:01:13.282Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-12-04T03:25:36.834Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

